package com.study.yygh.common.utils;

import com.study.yygh.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * @author tao
 * @create 2021-10-24 16:02
 * @Description 获取当前用户信息的工具类
 */
public class AuthContextHolder {

    // 获取当前用户id
    public static Long getUserId(HttpServletRequest request){
        // 从header获取token
        String token = request.getHeader("token");
        // jwt从token获取userid
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    // 获取当前用户名名字
    public static String getUserName(HttpServletRequest request){
        // 从header获取token
        String token = request.getHeader("token");
        // jwt从token获取userName
        String userName = JwtHelper.getUserName(token);
        return userName;
    }
}
